/***************************************************************
 * Name:      CamApp.cpp
 * Purpose:   Code for Application Class
 * Author:    Riku Maikola (rpm@ac-mapa.org)
 * Created:   2011-02-17
 * Copyright: Riku Maikola (rpm.ac-mapa.org)
 * License:
 **************************************************************/

#ifdef WX_PRECOMP
#include "wx_pch.h"
#endif

#ifdef __BORLANDC__
#pragma hdrstop
#endif //__BORLANDC__

#include "TerminalApp.h"
#include "TerminalMain.h"
#include <sstream>

IMPLEMENT_APP(CamApp);

bool CamApp::OnInit()
{
    //setlocale(LC_ALL,"C");
    CamMain* frame = new CamMain(0L);
    frame->Show();

    if(argc>1)
    {
        frame->PATH = argv[1];
        for(int a=2;a<argc;a++)
        {
            frame->PATH << _(" ") << argv[a];
        }

        std::string dir;

        //system(code.c_str());
        for(int a=0;a<1000;a++)
        {
            dir ="/dev/shm/maicam_";

            std::ostringstream convert;
            convert << a;
            dir += convert.str();
            if( mkdir(dir.c_str(),S_IRWXU|S_IRGRP|S_IXGRP) == 0)break;
        }

        frame->WORKDIR = wxString::FromUTF8(dir.c_str());

        std::string code = "cd ";
        code += dir;
        code += "\ntar -xf ";
        code += frame->PATH.mb_str();
        uint ulos =system(code.c_str());

    }
    else
    {
       return false;
    }


    frame->SetTitle(frame->PATH);
    return true;
}
